/**
 *
 *  加载资源模块，复写
 *
 */
class AppLoadController extends LoadController {
    public constructor() {
        super();
        this.defaultGroupName = CMDEvent.GROUP_SPLASH;
    }
    
    /**
     * 初始化加载资源事件
     */
    protected initListeners(): void {
        super.initListeners();
        this.addCommand(CMDEvent.LOAD_LOADING,this.loadGroup,this);
        this.addCommand(CMDEvent.SHOW_LOADING,this.showLoading,this);
    }
    
    /**
     * 子类复写该类处理其跳转逻辑
     */
    protected loadGroup(evt: egret.Event): void {
        var groupName: string = evt.data;
        if(groupName != null) {
            ResManager.get.loadGroup(groupName,this.resultGroupResLoadComplete,this.resultGroupResLoadProgress,this);
        }
    }

    private resultGroupResLoadComplete(groupName: string) {
        if(groupName.indexOf("question") != -1){
            this.dispatch(CMDEvent.LOAD_QUESTION_RES,groupName);
        } else if(groupName == CMDEvent.GROUP_RESULT){
            this.dispatch(CMDEvent.LOAD_RESULT_RES,groupName);
        }
    }

    private resultGroupResLoadProgress(progress: number,total: number) {
        this.loadingView.setProgress(progress,total);
    }

    private showLoading() {
        this.loadingView.show();
        this.root.addChild(this.loadingView);
    }
}
